{
  userDirs = {
    enable = true;
    createDirectories = true;
  };
  configFile = {
    "swayidle/config".text = ''
      timeout 330 "loginctl lock-session"
      before-sleep "noctalia-shell ipc call lockScreen lock"
      lock "niri msg action do-screen-transition; noctalia-shell ipc call lockScreen lock"
    '';
    "niri/config.kdl".text =
      lib.optionalString (
        osConfig.specialisation != { }
      ) "debug { render-drm-device \"/dev/dri/renderD129\"; }\n"
      + lib.optionalString (config.programs.noctalia-shell.settings.templates.niri or false
      ) "include \"noctalia.kdl\"\n"
      + ''
        input {
            touchpad {
                tap
                drag-lock
                natural-scroll
            }
            focus-follows-mouse max-scroll-amount="0%"
        }
        layout {
            shadow {
              on
              draw-behind-window true
            }
            default-column-width
        }
        cursor {
            xcursor-theme "${config.home.pointerCursor.name}"
            xcursor-size ${toString config.home.pointerCursor.size}
        }
        xwayland-satellite { path "${lib.getExe pkgs.xwayland-satellite-unstable}"; }
        binds {
            Mod+Shift+Slash { show-hotkey-overlay; }

            Mod+D       hotkey-overlay-title="File Manager"          { spawn "thunar"; }
            Mod+Return  hotkey-overlay-title="Terminal"              { spawn "kitty"; }
            Mod+T       hotkey-overlay-title="Quick Access Terminal" { spawn-sh "kitten quick-access-terminal"; }
            Super+Alt+L hotkey-overlay-title="Lock Screen"           { spawn-sh "loginctl lock-session"; }

            Mod+Space   hotkey-overlay-title="Application Launcher"  { spawn-sh "noctalia-shell ipc call launcher toggle"; }
            Mod+V       hotkey-overlay-title="Clipboard History"     { spawn-sh "noctalia-shell ipc call launcher clipboard"; }
            Mod+S       hotkey-overlay-title="Control Center"        { spawn-sh "noctalia-shell ipc call controlCenter toggle"; }
            Mod+N       hotkey-overlay-title="Notification History"  { spawn-sh "noctalia-shell ipc call notifications toggleHistory"; }
            Mod+Comma   hotkey-overlay-title="Settings"              { spawn-sh "noctalia-shell ipc call settings toggle"; }
            Mod+X       hotkey-overlay-title="Session Menu"          { spawn-sh "noctalia-shell ipc call sessionMenu toggle"; }

            Mod+TouchpadScrollDown { spawn-sh "noctalia-shell ipc call volume increase"; }
            Mod+TouchpadScrollUp   { spawn-sh "noctalia-shell ipc call volume decrease"; }

            XF86AudioRaiseVolume allow-when-locked=true { spawn-sh "noctalia-shell ipc call volume increase"; }
            XF86AudioLowerVolume allow-when-locked=true { spawn-sh "noctalia-shell ipc call volume decrease"; }
            XF86AudioMute        allow-when-locked=true { spawn-sh "noctalia-shell ipc call volume muteOutput"; }
            XF86AudioMicMute     allow-when-locked=true { spawn-sh "noctalia-shell ipc call volume muteInput"; }
            XF86MonBrightnessUp   allow-when-locked=true { spawn-sh "noctalia-shell ipc call brightness increase"; }
            XF86MonBrightnessDown allow-when-locked=true { spawn-sh "noctalia-shell ipc call brightness decrease"; }
            XF86AudioPlay allow-when-locked=true { spawn-sh "noctalia-shell ipc call media playPause"; }
            XF86AudioPrev allow-when-locked=true { spawn-sh "noctalia-shell ipc call media previous"; }
            XF86AudioNext allow-when-locked=true { spawn-sh "noctalia-shell ipc call media next"; }

            Mod+O repeat=false { toggle-overview; }
            Mod+Q repeat=false { close-window; }

            Mod+Home      { focus-column-first; }
            Mod+End       { focus-column-last; }
            Mod+Ctrl+Home { move-column-to-first; }
            Mod+Ctrl+End  { move-column-to-last; }

            ${builtins.concatStringsSep "\n    " (
              builtins.concatMap (x: [
                "Mod+${x}      { focus-workspace ${x}; }"
                "Mod+Ctrl+${x} { move-column-to-workspace ${x}; }"
              ]) (lib.stringToCharacters "123456789")
            )}

            ${builtins.concatStringsSep "\n    " (
              builtins.concatMap
                (x: [
                  "Mod+${x.name}            { focus-column-${x.value}; }"
                  "Mod+Ctrl+${x.name}       { move-column-${x.value}; }"
                  "Mod+Shift+${x.name}      { focus-monitor-${x.value}; }"
                  "Mod+Shift+Ctrl+${x.name} { move-column-to-monitor-${x.value}; }"
                ])
                (
                  lib.attrsToList {
                    Left = "left";
                    Right = "right";
                    H = "left";
                    L = "right";
                  }
                )
            )}
            ${builtins.concatStringsSep "\n    " (
              builtins.concatMap
                (x: [
                  "Mod+${x.name}            { focus-window-or-workspace-${x.value}; }"
                  "Mod+Ctrl+${x.name}       { move-window-${x.value}-or-to-workspace-${x.value}; }"
                  "Mod+Shift+${x.name}      { focus-monitor-${x.value}; }"
                  "Mod+Shift+Ctrl+${x.name} { move-column-to-monitor-${x.value}; }"
                ])
                (
                  lib.attrsToList {
                    Down = "down";
                    Up = "up";
                    J = "down";
                    K = "up";
                  }
                )
            )}

            ${builtins.concatStringsSep "\n    " (
              builtins.concatMap
                (x: [
                  "Mod+${x.name}       { focus-workspace-${x.value}; }"
                  "Mod+Ctrl+${x.name}  { move-column-to-workspace-${x.value}; }"
                  "Mod+Shift+${x.name} { move-workspace-${x.value}; }"
                ])
                (
                  lib.attrsToList {
                    Page_Down = "down";
                    Page_Up = "up";
                    U = "down";
                    I = "up";
                  }
                )
            )}

            Mod+WheelScrollDown      cooldown-ms=150 { focus-workspace-down; }
            Mod+WheelScrollUp        cooldown-ms=150 { focus-workspace-up; }
            Mod+Ctrl+WheelScrollDown cooldown-ms=150 { move-column-to-workspace-down; }
            Mod+Ctrl+WheelScrollUp   cooldown-ms=150 { move-column-to-workspace-up; }

            Mod+WheelScrollRight      { focus-column-right; }
            Mod+WheelScrollLeft       { focus-column-left; }
            Mod+Ctrl+WheelScrollRight { move-column-right; }
            Mod+Ctrl+WheelScrollLeft  { move-column-left; }

            Mod+Shift+WheelScrollDown      { focus-column-right; }
            Mod+Shift+WheelScrollUp        { focus-column-left; }
            Mod+Ctrl+Shift+WheelScrollDown { move-column-right; }
            Mod+Ctrl+Shift+WheelScrollUp   { move-column-left; }

            Mod+BracketLeft  { consume-or-expel-window-left; }
            Mod+BracketRight { consume-or-expel-window-right; }
            Mod+Period       { expel-window-from-column; }

            Mod+R       { switch-preset-column-width; }
            Mod+Shift+R { switch-preset-window-height; }
            Mod+Ctrl+R  { reset-window-height; }

            Mod+F            { maximize-column; }
            Mod+Shift+F      { fullscreen-window; }
            Mod+Ctrl+F       { expand-column-to-available-width; }
            Mod+Ctrl+Shift+F { toggle-windowed-fullscreen; }

            Mod+C      { center-column; }
            Mod+Ctrl+C { center-visible-columns; }

            Mod+Minus       { set-column-width "-10%"; }
            Mod+Equal       { set-column-width "+10%"; }
            Mod+Shift+Minus { set-window-height "-10%"; }
            Mod+Shift+Equal { set-window-height "+10%"; }

            Mod+Shift+T { toggle-window-floating; }
            Mod+Shift+V { switch-focus-between-floating-and-tiling; }

            Mod+W { toggle-column-tabbed-display; }

            Print      { screenshot; }
            Ctrl+Print { screenshot-screen write-to-disk=false; }
            Alt+Print  { screenshot-window write-to-disk=false; }

            Mod+Escape allow-inhibiting=false { toggle-keyboard-shortcuts-inhibit; }

            Mod+Shift+E     { quit; }
            Ctrl+Alt+Delete { quit; }

            Mod+Shift+P { power-off-monitors; }
        }
        window-rule {
            match app-id="firefox$" title="^(画中画|Picture-in-Picture)$|^(关于|About)"
            open-floating true
        }
        layer-rule {
            match namespace="^noctalia-overview*"
            place-within-backdrop true
        }
      '';
  };
}
